package com.example.demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: demo
 * @author: JCM
 * @create: 2023-02-25 14:27
 * @description:
 **/
@Controller // 当前类是控制器
@ResponseBody // 返回的是数据，而非页面
@PropertySource(value = "application.properties",encoding = "utf8")
public class TestController {

    @Value("${mytest}")
    private String mytest;

    @RequestMapping("/hi") // url 路由注册
    public String sayHi(String name) {
        // 判断 name 是否有长度
        if(!StringUtils.hasLength(name)) {
            name = "张三";
        }
        return "你好：" + name;
    }

    @RequestMapping("/getconfig")
    public String getConfig() {
        return mytest;
    }
}
